<!DOCTYPE html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
    >
<meta charset="UTF-8">
<head th:include="include :: header"></head>

<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-body">
                <div class="fixed-table-toolbar">
                    <div class="columns pull-right">
                        <button class="btn btn-success" onclick="query()">查询</button>
                        <button class="btn btn-success" onclick="resetParam()">重置</button>
                    </div>

                    <div class="columns pull-right col-md-2 nopadding">
                        <input class="form-control" type="text" id="name" placeholder="会员名称" tabindex="2"/>
                    </div>
                    <div class="columns pull-right col-md-4 nopadding">
                        <input class="form-control" type="text" id="idCardNo" placeholder="身份证号" tabindex="1"/>
                    </div>
                </div>
                <table id="exampleTable" data-mobile-responsive="true">
                </table>
            </div>
        </div>
    </div>
<!--shiro控制bootstraptable行内按钮看见性 来自bootdo的创新方案 -->
    <div>
        <script type="text/javascript">
            var s_pass_h = '';
            var s_reject_h = '';
            var s_rejectDtl_h = '';
        </script>
    </div>
    <div shiro:hasPermission="mp:cash:index">
        <script type="text/javascript">
            s_pass_h = '';
            console.log('s_pass_h',s_pass_h);
        </script>
    </div>
    <div shiro:hasPermission="mp:cash:index">
        <script type="text/javascript">
            s_reject_h = '';
            console.log('s_reject_h',s_reject_h);
        </script>
    </div>
    <div shiro:hasPermission="mp:cash:index">
        <script type="text/javascript">
            s_rejectDtl_h = '';
            console.log('s_rejectDtl_h',s_rejectDtl_h);
        </script>
    </div>

</div>
<div th:include="include :: footer"></div>
<script type="text/javascript">

    var prefix = "/mp/cash";
    $(function () {
        load();
    });

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get', // 服务器数据的请求方式 get or post
                    url: prefix + "/list", // 服务器数据的加载地址
                    //showRefresh: true,
                    //	showToggle : true,
                    //	showColumns : true,
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: true, // 设置为true会有隔行变色效果
                    dataType: "json", // 服务器返回的数据类型
                    pagination: true, // 设置为true会在底部显示分页条
                    // queryParamsType : "limit",
                    // //设置为limit则会发送符合RESTFull格式的参数
                    singleSelect: false, // 设置为true将禁止多选
                    // contentType : "application/x-www-form-urlencoded",
                    // //发送到服务器的数据编码类型
                    pageSize: 10, // 如果设置了分页，每页数据条数
                    pageNumber: 1, // 如果设置了分布，首页页码
                    //search : true, // 是否显示搜索框
                    showColumns: false, // 是否显示内容下拉框（选择显示的列）
                    sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者 "server"
                    queryParams: function (params) {
                        return {
                            //说明：传入后台的参数包括offset开始索引，limit步长，sort排序列，order：desc或者,以及所有列的键值对
                            limit: params.limit,
                            offset: params.offset
                        };
                    },
                    // //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果
                    // queryParamsType = 'limit' ,返回参数必须包含
                    // limit, offset, search, sort, order 否则, 需要包含:
                    // pageSize, pageNumber, searchText, sortName,
                    // sortOrder.
                    // 返回false将会终止请求
                    columns: [
                        {
                            field: 'name',
                            title: '会员名称'
                        },
                        {
                            field: 'idCardNo',
                            title: '身份证号'
                        },
                        {
                            field: 'alipayAccount',
                            title: '支付宝账号'
                        },
                        {
                            field: 'cashAmt',
                            title: '提现金额'
                        },
                        {
                            field: 'createTime',
                            title: '提现日期'
                        },
                        {
                            field: 'cashStatus',
                            title: '提现状态',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '<span class="label label-info">待审核</span>';
                                } else if (value == '1') {
                                    return '<span class="label label-success">审核通过(提现成功)</span>';
                                } else if (value == '2') {
                                    return '<span class="label label-danger">审核不通过</span>';
                                }
                            }
                        },
                        {
                            title: '操作',
                            field: 'id',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var dtl = "";
                                if (row.cashStatus == 0) {
                                    var g = '<a class="btn btn-primary btn-sm ' + s_pass_h + '" href="#" mce_href="#" title="通过" onclick="passAudit(\''
                                        + row.id
                                        + '\')"><i class="fa fa-edit">通过</i></a> ';
                                    var h = '<a class="btn btn-primary btn-sm ' + s_reject_h + '" href="#" mce_href="#" title="驳回" onclick="reject(\''
                                        + row.id
                                        + '\')"><i class="fa fa-edit">驳回</i></a> ';
                                    dtl = g + h;
                                } else if (row.cashStatus == 2) {
                                    var g = '<a class="btn btn-primary btn-sm ' + s_rejectDtl_h + '" href="#" mce_href="#" title="驳回原因" onclick="rejectDetail(\''
                                        + row.rejectReason
                                        + '\')"><i class="fa fa-edit">驳回原因</i></a> ';
                                    var h = "";
                                    dtl = g + h;
                                } else {
                                    return dtl;
                                }
                                return dtl;
                            }
                        }]
                });
    }

    function reLoad() {
        var opt = {
            query: {
                limit: 10,
                offset: 0
            }
        };
        $('#exampleTable').bootstrapTable('refresh', opt);
    }


    function query() {
        var opt = {
            query: {
                name: $('#name').val(),
                idCardNo: $('#idCardNo').val(),
            }
        };
        $('#exampleTable').bootstrapTable('refresh', opt);
    }

    function resetParam() {
        $('#name').val('');
        $('#idCardNo').val('');
        var opt = {
            query: {
                limit: 10,
                offset: 0
            }
        };
        $('#exampleTable').bootstrapTable('refresh', opt);
    }

    //通过审核
    function passAudit(id) {
        layer.confirm('确定通过审核吗？', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                url: prefix + "/audit",
                type: "post",
                data: {
                    'id': id,
                    'cashStatus': 1,
                },
                success: function (r) {
                    if (r.code == 0) {
                        layer.msg(r.msg);
                        $('#exampleTable').bootstrapTable('refresh');
                    } else {
                        layer.msg(r.msg);
                    }
                }
            });
        })
    }

    //驳回审核
    function reject(id) {
        layer.prompt({title: '驳回原因', formType: 2},
            function (text, index) {
                if (text == '' || text == null) {
                    layer.msg("驳回原因不能为空");
                    return false;
                }
                $.ajax({
                    url: prefix + "/audit",
                    type: "post",
                    data: {
                        'id': id,
                        'cashStatus': 2,
                        'rejectReason': text
                    },
                    success: function (r) {
                        if (r.code == 0) {
                            layer.msg(r.msg);
                            $('#exampleTable').bootstrapTable('refresh');
                            layer.close(index);
                        } else {
                            layer.msg(r.msg);
                            layer.close(index);
                        }

                    }
                });
            });

    }

    //驳回原因查看
    function rejectDetail(rejectReason) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: false,
            area: '300px;',
            shade: 0.8,
            id: 'LAY_layuipro', //设定一个id，防止重复弹出
            btn: ['我知道了'],
            btnAlign: 'c',
            moveType: 1,//拖拽模式，0或者1
            content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">驳回原因：<br>' + rejectReason + '</div>'
            ,
        });
    }
</script>
</body>

</body>
</html>